import numpy as np
a1 = np.array([[1, 2], [3, 4]])
a2 = np.array([[1],[2]])
a1 @ a2
b1 = np.array([[1, -1], [1, 1]])
b2 = np.array([[1, 0], [1, 1]])
b1 @ b2
def toRads(a):
return a * np.pi/180
def rotate(matrix, a):
a = toRads(a)
rot_a = np.array([[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]])
return matrix @ rot_a
import matplotlib.pyplot as plt
def plot(matrix):
ax = plt.subplot(1, 1, 1)
ax.plot(matrix[:, 0], matrix[:, 1], marker='o')
ax.set_aspect('equal')
plt.show()
A = np.array([[0, 0], [0, 2], [1, 1]])
rotated_A1 = rotate(A, 45)
plot(rotated_A1)
rotated_A2 = rotate(A, -225)
plot(rotated_A2)
rotated_A3 = rotate(A, 83)
plot(rotated_A3)
obj = np.array([[0, 1], [3, 5], [4, 3], [2, 1]])
obj
plot(obj)
plot(rotate(obj, 25))
plot(rotate(obj, 47))
plot(rotate(obj, 93))
import pandas as pd
data = pd.read_csv('./crazy-hat.tsv', '\t')
data.head()
data.group.unique()
for g in data.group.unique():
group = data[data['group'] == g]
plt.plot(group.x, group.y)
def rotate_hat(a):
new = rotate(data[['x', 'y']], a)
data['new_x'] = new[0]
data['new_y'] = new[1]
return data
def plot_hat(a):
rotate_hat(a)
for g in data.group.unique():
group = data[data['group'] == g]
plt.plot(group.new_x, group.new_y)
plot_hat(45)
plot_hat(90)
plot_hat(75)
m = np.array([[2, 4], [5, 7]])
t = data[['x', 'y']] @ m
data['new_x'] = t[0]
data['new_y'] = t[1]
for g in data.group.unique():
group = data[data['group'] == g]
plt.plot(group.new_x, group.new_y)
ds = pd.read_csv('./ccpp.csv.bz2', '\t')
ds.head()
plt.scatter(ds.AT, ds.PE)
import statsmodels.formula.api as smf
r = smf.ols(formula = 'PE ~ AT', data=ds).fit()
r.summary()
PE(AT) = 497.03 - 2.17 * AT + e
For every additional degree of temperature, the net energy output decreases by 2.17 MW. This is statistically significant due to the 0 p-value, indicating that there is almost a 0 probability that this relationship occurs purely due to chance
plt.scatter(ds.AT, ds.PE)
ax = np.linspace(ds['AT'].min(), ds['AT'].max())
hatPE = r.params[0] + r.params[1] * ax
plt.plot(ax, hatPE, color='red')
plt.show()
plt.scatter(ds.AP, ds.PE)
r = smf.ols(formula = 'PE ~ AP', data=ds).fit()
r.summary()
PE(AP) = -1055.26 + 1.49 * AP + e
This means that for every additional millibar of ambient pressure, the energy output increases by 1.49 MW. This is statistically significant because the p-value is 0, meaning that there is almost no chance this relationship is due to chance
plt.scatter(ds.AP, ds.PE)
ax = np.linspace(ds['AP'].min(), ds['AP'].max())
hatPE = r.params[0] + r.params[1] * ax
plt.plot(ax, hatPE, color='red')
plt.show()
plt.scatter(ds.RH, ds.PE)
r = smf.ols(formula = 'PE ~ RH', data=ds).fit()
r.summary()
PE(RH) = 420.96 + 0.46 * RH + e
This means that for every additional percent of relative humidity, the net energy output increases by 0.46 MW. This is a statistically significant relationship because the p-value is close to 0, indicating that there is almost no chance this relationship is due to chance
plt.scatter(ds.RH, ds.PE)
ax = np.linspace(ds['RH'].min(), ds['RH'].max())
hatPE = r.params[0] + r.params[1] * ax
plt.plot(ax, hatPE, color='red')
plt.show()
plt.scatter(ds.V, ds.PE)
r = smf.ols(formula = 'PE ~ V', data=ds).fit()
r.summary()
PE(V) = 517.8 - 1.17 * V + e
This means that for every additional cm Hg of exhaust vacuum, there is 1.17 MW less energy output. This relationship is statistically significant because the P value is 0, indicating that there is almost no chance the relationship is random.
plt.scatter(ds.V, ds.PE)
ax = np.linspace(ds['V'].min(), ds['V'].max())
hatPE = r.params[0] + r.params[1] * ax
plt.plot(ax, hatPE, color='red')
plt.show()